<template>
  <div class="px-[30px] py-5 user-drawing w-full flex flex-col items-center">
    <div
      class="info-top mt-[30px] w-[920px] h-[222px] flex flex-col justify-center items-center"
      :style="{
        'background-image': `url('${appStore.getUserDrawingBg}')`,
      }"
    >
      <div class="toDrawing">
        <div class="flex items-center cursor-pointer">
          <span class="mr-[10px]" style="line-height: 1em">开始创作</span
          ><el-icon :size="20" color="#F86E07"><Right /></el-icon>
        </div>
      </div>
    </div>
    <div
      class="info-bottom mt-[20px] w-[920px] flex flex-col justify-center items-center"
    >
      <div class="w-full" style="height: calc(100% - 500px)">
        <div class="task-lists flex-1 flex justify-between items-center">
          <div class="left flex items-center">
            <el-image class="w-[24px] h-[24px]" :src="drawingImg"></el-image>
            <div class="title mr-[20px] text-[var(--color-btn-text)]">
              我的创作
            </div>
            <div>
              <el-select
                class="w-[150px]"
                v-model="type"
                placeholder="Select"
                @change="
                  (e) => {
                    taskIndex = e;
                  }
                "
              >
                <el-option
                  v-for="item in taskLists"
                  :key="item.value"
                  :label="item.name"
                  :value="item.value"
                />
              </el-select>
            </div>
          </div>
          <div
            @click="addType"
            class="right w-[112px] h-[34px] bg-[var(--el-bg-color-base)] rounded-[8px] cursor-pointer flex justify-center items-center text-[var(--color-btn-text)]"
          >
            <el-image class="w-[18px] h-[18px]" :src="addImg"></el-image>
            <span class="ml-[8px]">创建合集</span>
          </div>
          <!-- <div
            v-for="(item, index) in taskLists"
            :key="index"
            class="task-item"
            :class="{
              'task-item--active': item.value === taskIndex,
            }"
            @click="taskIndex = item.value"
          >
            {{ item.name }}
          </div> -->
        </div>

        <div
          class="h-full"
          v-loading="isReceiving"
          element-loading-text="请求生成中"
        >
          <DrawingTabs :state="taskIndex" @pagination="setTaskRecordFunc">
          </DrawingTabs>
        </div>
      </div>
    </div>
  </div>
</template>
<script lang="ts" setup>
import { Right } from "@element-plus/icons-vue";
import { backgroundImage } from "html2canvas/dist/types/css/property-descriptors/background-image";
// import { useIndexEffect } from "./hooks/useInfoEffect";
import DrawingControl from "./component/drawing-control/index.vue";
import DrawingTabs from "./component/drawing-tabs.vue";
// eslint-disable-next-line @typescript-eslint/no-unused-vars
import DrawingResult from "./component/drawing-result/index.vue";
import drawingImg from "@/assets/images/icon/drawing.png";
import addImg from "@/assets/images/icon/add.png";
import { ElMessage, ElMessageBox } from "element-plus";
import { mydrawList, myClassList, addClass } from "@/api/user";
import {useAppStore} from '@/stores/app'
const appStore = useAppStore()
// const { isReceiving, setTaskRecordFunc } =
//   useIndexEffect();
const taskLists = ref<any>([]);
const type = ref(1);
const addType = () => {
  ElMessageBox.prompt("创建集合", "创建", {
    confirmButtonText: "确定",
    cancelButtonText: "取消",
    inputPattern: /\S/,
    inputErrorMessage: "请输入集合名",
  })
    .then(({ value }) => {
      addClass({ name: value, drawRecordsId:0,state: (taskLists.value[taskLists.value.length - 1].value + 1)}).then((res) => {
        getClassList()
        ElMessage({
          type: "success",
          message: "创建成功",
        });
      });
    })
    .catch(() => {});
};

const setTaskRecordFunc = (func: Function) => {
  func();
};
const getClassList = async () => {
  taskLists.value = (await myClassList())
    .map((item: any) => {
      return {
        name: item.name,
        value: item.state,
      };
    })
    .sort((a: any, b: any) => {
      return a.value - b.value;
    });
};

getClassList()
</script>
<style lang="scss" scoped>
.toDrawing {
  border-radius: 8px;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 350px;
  height: 40px;
  border: 2px solid #f86e07;
  color: #f86e07;
  background: rgba(0, 0, 0, 0.5);
  text-align: center;
  span {
    letter-spacing: 1px;
  }
}

.info-top {
  border-radius: 8px;
  background-size: 920px 222px;
}

.task-lists {
  .task-item {
    display: inline-block !important;
    line-height: 30px;
    border-radius: 30px;
    box-shadow: 0 2px 6px #ebeefd;
    text-align: center;
    height: 30px;
    padding: 0px 24px;
    font-size: 14px;
    margin: 10px 0;
    margin-left: 10px;
    cursor: pointer;
    @apply line-clamp-1 text-tx-primary;
    &--active {
      @apply text-btn-text;
      box-shadow: 0 3px 6px #ebeefd;
      background: linear-gradient(
        87.73deg,
        var(--gradient-1) 0%,
        var(--gradient-2) 100%
      );
    }
  }
}
</style>
